package info.ipeanut.toffeepulltorefresh;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;

import java.util.ArrayList;

/**
 */
public class MainActivity extends AppCompatActivity {

    RecyclerView recyclerView;
    ArrayList<String> arrayList;
    HeaderPullLayout pulllayout;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        main1();main2();
        setContentView(R.layout.activity_main);

        recyclerView = (RecyclerView) findViewById(R.id.id_recyclerview);
        pulllayout = (HeaderPullLayout) findViewById(R.id.pulllayout);
        pulllayout.setPullListener(new PullListener() {
            @Override
            public void onPullingDown(float fraction, int scrollY) {
                Log.d("onPullingDown",fraction+"==="+scrollY);
            }

            @Override
            public void onScrollBack(float fraction, int scrollY) {
                Log.d("onScrollBack",fraction+"==="+scrollY);

            }

            @Override
            public void onRefresh() {
                Toast.makeText(MainActivity.this, "refresh", Toast.LENGTH_SHORT).show();

            }
        });

        findViewById(R.id.tabs).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(MainActivity.this, "tabs", Toast.LENGTH_SHORT).show();

            }
        });

        initData();
    }

    private void initData() {
        arrayList = new ArrayList<>();
        for (int i = 0; i < 30; i++) {
            arrayList.add("item......"+i);
        }
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recyclerView.setAdapter(new MyAdapter(arrayList));
    }


    public static class MyAdapter extends RecyclerView.Adapter<Holder>{
        ArrayList<String> arrayList;

        public MyAdapter(ArrayList<String> arrayList) {
            this.arrayList = arrayList;
        }

        @Override
        public Holder onCreateViewHolder(ViewGroup parent, int viewType) {
            View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_holder,parent,false);
            return new Holder(view);
        }

        @Override
        public void onBindViewHolder(Holder holder, int position) {
            holder.tv_item.setText(arrayList.get(position));

        }

        @Override
        public int getItemCount() {
            return arrayList.size();
        }
    }

    public static class Holder extends RecyclerView.ViewHolder{
        public TextView tv_item;

        public Holder(View itemView) {
            super(itemView);
            tv_item = (TextView) itemView.findViewById(R.id.tv_item);
        }
    }

    public static void main1() {
        String x = new String("goeasyway");
        change(x);
        System.out.println(x);
    }

    public static void change(String x) {
        x = "even";
        System.out.println("change--"+x);

    }

    public static void main2() {
        int x = 2;
        change(x);
        System.out.println("--"+x);
    }

    public static void change(int x) {
        x = 5;
        System.out.println("change--"+x);

    }

}
